package com.wj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wj.dao.MenuRoleMapper;
import com.wj.pojo.MenuRole;
import com.wj.pojo.RespBean;
import com.wj.service.IMenuRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wj
 * @since 2022-03-06
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {
    @Resource
    private MenuRoleMapper menuRoleMapper;

    /**
     * 更新角色的菜单
     *
     * @param rid
     * @param mids
     * @return
     */
    @Override
    public RespBean updateRoleMenu(Integer rid, Integer[] mids) {
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        if (ArrayUtils.isEmpty(mids)) {
            return RespBean.success("更新成功");
        }
        if (menuRoleMapper.insertRecord(rid, mids) > 0) {
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
